package com.khalil.kkadmin.module.ai.application;

import com.khalil.kkadmin.common.util.JsonUtil;
import com.khalil.kkadmin.common.web.RespResult;
import com.khalil.kkadmin.module.ai.application.domain.AiApplication;
import com.khalil.kkadmin.module.ai.application.dto.AiApplicationCreateDto;
import com.khalil.kkadmin.module.ai.application.service.AiApplicationManager;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ai/application")
public class AiApplicationController {
    private final AiApplicationManager aiApplicationManager;

    public AiApplicationController(AiApplicationManager aiApplicationManager) {
        this.aiApplicationManager = aiApplicationManager;
    }

    @GetMapping("list")
    public RespResult<List<AiApplication>> list() {
        return RespResult.ok(aiApplicationManager.list());
    }

    @GetMapping("/{id}")
    public RespResult<AiApplication> get(@PathVariable Long id) {
        return RespResult.ok(aiApplicationManager.get(id));
    }

    @PostMapping("")
    public RespResult<AiApplication> add(@RequestBody AiApplicationCreateDto createDto) {
        AiApplication aiApplication = aiApplicationManager.create(createDto);
        return RespResult.ok(aiApplication);
    }

    @PutMapping("")
    public RespResult<AiApplication> edit(@RequestBody AiApplication aiApplication) {
        return RespResult.ok(aiApplicationManager.update(aiApplication));
    }

    @DeleteMapping("/{id}")
    public RespResult<Void> delete(@PathVariable Long id) {
        aiApplicationManager.delete(id);
        return RespResult.ok(null);
    }
}
